﻿using PC.AzureMultiApp.Core.Helpers;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.IO;

namespace Core.Test
{
    [TestClass()]
    public class CommandsTest
    {
        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        [TestMethod()]
        public void LaunchAfterAndNoWaitCmdIfExistsTest()
        {
            string applicationPath = Path.Combine(testContextInstance.DeploymentDirectory, "sampledir");
            Commands.LaunchAfterAndNoWaitCmdIfExists(applicationPath);
        }

        [TestMethod()]
        public void LaunchAfterAndWaitCmdIfExists()
        {
            string applicationPath = Path.Combine(testContextInstance.DeploymentDirectory, "sampledir");
            Commands.LaunchAfterAndWaitCmdIfExists(applicationPath);
        }

        [TestMethod()]
        public void LaunchAfterAndNoWaitCmdIfExists()
        {
            string applicationPath = Path.Combine(testContextInstance.DeploymentDirectory, "sampledir");
            Commands.LaunchAfterAndNoWaitCmdIfExists(applicationPath);
        }


        [TestMethod()]
        [DeploymentItem("PC.AzureMultiApp.Core.dll")]
        public void LaunchCmdIfExists_FileNoExists_Test()
        {
            string applicationPath = Path.Combine(testContextInstance.DeploymentDirectory, "sampledir");
            if (!Directory.Exists(applicationPath))
                Directory.CreateDirectory(applicationPath);

            string filename = "filename.cmd";

            bool wait = false; 
            bool expected = true; 
            bool actual;
            actual = Commands_Accessor.LaunchCmdIfExists(applicationPath, filename, wait);
            Assert.AreEqual(expected, actual);

        }

        [TestMethod()]
        [DeploymentItem("PC.AzureMultiApp.Core.dll")]
        public void LaunchCmdIfExists_DirectoryNoExists_Test()
        {
            string applicationPath = Path.Combine(testContextInstance.DeploymentDirectory, "dirnoexists");

            string filename = "filename.cmd";

            bool wait = false;
            bool expected = true;
            bool actual;
            actual = Commands_Accessor.LaunchCmdIfExists(applicationPath, filename, wait);
            Assert.AreEqual(expected, actual);

        }

        [TestMethod()]
        [DeploymentItem("PC.AzureMultiApp.Core.dll")]
        [DeploymentItem("commands\\setup.cmd", "commands")]
        public void LaunchCmdIfExistsTest()
        {
            string dir = testContextInstance.TestDeploymentDir;
            string applicationPath = Path.Combine(testContextInstance.DeploymentDirectory, "commands");

            string filename = "setup.cmd";

            bool wait = false;
            bool expected = true;
            bool actual;
            actual = Commands_Accessor.LaunchCmdIfExists(applicationPath, filename, wait);
            Assert.AreEqual(expected, actual);
        }
    }
}
